//
//  BQShopModelArrayManager.m
//  BeeQuick
//
//  Created by student on 2017/7/14.
//  Copyright © 2017年 BecomeRich. All rights reserved.
//

#import "BQShopModelArrayManager.h"

@implementation BQShopModelArrayManager


+ (instancetype)manager{
    
    static id  instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        instance = [[self alloc]init];
    });
    
    return instance;
}

- (instancetype)init{
    
    if (self = [super init]) {
        self.modelArray = [NSMutableArray array];
        for (int i = 0; i < 3; i++) {
            BQProductModel *model = [[BQProductModel alloc]init];
            [self.modelArray addObject:model];
        }
    }
    return self;
}
//添加模型
- (void)shopModelArrayManagerAddWithModel:(BQProductModel *)model{
    if (model.count == 0) {
        [self.modelArray addObject:model];
    }
}
//减少模型
- (void)shopModelArrayManagerReduceWithModel:(BQProductModel *)model{
    if (self.modelArray.count != 0) {
        if (model.count <= 1) {
            [self.modelArray removeObject:model];
        }
    }
}

//订单总数
- (NSInteger)shopManagerShowModelCount{
    NSInteger count = 0;
    for (int i = 0; i < self.modelArray.count; i++) {
      
        BQProductModel *model = self.modelArray[i];
        count +=  model.count;
        
    }
    return count;
}

- (void)tabBarShowCount{
    NSInteger count = 0;
    for (int i = 0; i < self.modelArray.count; i++) {
        
        BQProductModel *model = self.modelArray[i];
        count +=  model.count;
    }

    if (self.managerBlock != nil) {
        self.managerBlock(count);
    }
}

- (void)shopClick{
    
    if (self.shopBlock != nil) {
        self.shopBlock();
    }
}

- (NSString *)showSumPrice{
    
    CGFloat  money = 0;
    for (int i = 3; i < [BQShopModelArrayManager manager].modelArray.count; i++) {
        BQProductModel  *model = [[BQProductModel alloc]init];
        model = [BQShopModelArrayManager manager].modelArray[i];
        money += model.price * model.count;
    }
    return [NSString stringWithFormat:@" %.2f",money];
}


@end
